using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using Gavel.Common.Utilities.Const;

namespace Gavel.Common.Component.ViewModel;

/// <summary>
/// 消息通知视图模型
/// </summary>
public class NotificationViewModel : INotifyPropertyChanged
{
    /// <summary>
    /// 属性修改事件
    /// </summary>
    public event PropertyChangedEventHandler? PropertyChanged;

    /// <summary>
    /// 消息类型
    /// </summary>
    private readonly NotifyType _type = NotifyType.Info;

    /// <summary>
    /// 消息类型
    /// </summary>
    public NotifyType Type
    {
        get => _type;
        init
        {
            _type = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Icon)));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Background)));
        }
    }

    /// <summary>
    /// 消息
    /// </summary>
    private readonly string _message = string.Empty;

    /// <summary>
    /// 消息
    /// </summary>
    public string Message
    {
        get => _message;
        init
        {
            _message = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Message)));
        }
    }

    /// <summary>
    /// 图标
    /// </summary>
    public Geometry Icon => Type switch
    {
        NotifyType.Error => Application.Current.FindResource("Error") as Geometry ?? Geometry.Empty,
        NotifyType.Warning => Application.Current.FindResource("Warning") as Geometry ?? Geometry.Empty,
        NotifyType.Success => Application.Current.FindResource("Success") as Geometry ?? Geometry.Empty,
        _ => Application.Current.FindResource("Info") as Geometry ?? Geometry.Empty
    };

    /// <summary>
    /// 图标颜色
    /// </summary>
    public Brush IconBrush => Type switch
    {
        NotifyType.Error => Brushes.LightCoral,
        NotifyType.Warning => Brushes.LightSalmon,
        NotifyType.Success => Brushes.LightSkyBlue,
        _ => Brushes.LightGray
    };

    /// <summary>
    /// 背景色
    /// </summary>
    public Brush Background => Type switch
    {
        NotifyType.Error => Application.Current.FindResource("BrushRed20") as Brush ?? Brushes.White,
        NotifyType.Warning => Application.Current.FindResource("BrushOrange20") as Brush ?? Brushes.White,
        NotifyType.Success => Application.Current.FindResource("BrushGreen20") as Brush ?? Brushes.White,
        _ => Application.Current.FindResource("BrushWhite20") as Brush ?? Brushes.White
    };
}